﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AIFSContentManagementSystem.DomainObjects
{
    public sealed class NumericCriterionExpression : CriterionExpression
    {
        public override string DataType
        {
            get
            {
                return "NUMERIC";
            }
        }

        protected override bool CanCompare(CriterionExpression other)
        {
            if (!(other is NumericCriterionExpression))
                return false;

            Decimal dec;

            bool tryParse = Decimal.TryParse(this.RightOperand, out dec);
            if (!tryParse)
                return false;

            tryParse = Decimal.TryParse(other.RightOperand, out dec);
            if (!tryParse)
                return false;

            return true;
        }

        protected override int CompareTo(CriterionExpression other)
        {
            Decimal thisNumber;
            Decimal otherNumber;

            Decimal.TryParse(this.RightOperand, out thisNumber);
            Decimal.TryParse(other.RightOperand, out otherNumber);

            return thisNumber.CompareTo(otherNumber);
        }
    }
}
